package com.example.stujava.module.xiangxue.generic;

import com.example.stujava.module.xiangxue.generic.entity.Apple;
import com.example.stujava.module.xiangxue.generic.entity.Food;
import com.example.stujava.module.xiangxue.generic.entity.Fruits;
import com.example.stujava.module.xiangxue.generic.entity.GenericType;
import com.example.stujava.module.xiangxue.generic.entity.HongFuShi;

public class WildcardCharGeneric {

    public static void main(String[] args) {
        //extends通配符 限定传入数据的上界，安全的访问数据
        GenericType<? extends Fruits> c = new GenericType<>();
        Apple apple = new Apple();
//        c.setData(apple);
        Food food = new Food();
//        c.setData(food);
        Fruits fruits = c.getData();
        //super通配符限定传入数据的下届，安全的写入数据
        GenericType<? super Apple> appleGeneric = new GenericType<>();
        appleGeneric.setData(new HongFuShi());
        appleGeneric.setData(new Apple());
        Object object = appleGeneric.getData();
    }
}
